#include <head.h>

int main(int argc, char const *argv[])
{
    int fd = open("111.txt", O_CREAT | O_RDWR, 0666);
    int fd_T = open("T.txt", O_CREAT | O_RDWR, 0666);

    flock(fd, LOCK_EX);

    int i = 10;
    int T_num = 0;
    char buff[32];
    read(fd_T, &T_num, sizeof(int));

    lseek(fd, T_num - 10, SEEK_SET);

    while (i--)
    {

        buff[32] = 0;
        sleep(1);
        write(fd, buff, 1);
    }
    T_num = lseek(fd, 0, SEEK_END);

    lseek(fd_T, 0, SEEK_SET);
    write(fd_T, &T_num, sizeof(int));
    flock(fd, LOCK_UN);

    close(fd);
    close(fd_T);

    return 0;
}